<?php
/*
通用分类
*/
class Con_report extends Acan{
	public $defaultAct='order';
	function __construct($ainfo=null){
		parent::__construct($ainfo=null);
		if(empty($this->id) || $this->id == '*'){$this->id = '0';}
	}
	function Act_order(){
		$this->model = Afun_db()->model(Adb_asale_order);
		$obj = Afun_acan_new('list');
		$key_name = $this->model->key_name;
		$columnrr = array("oid"=>"","time_add"=>"","products"=>"","cost"=>"","price"=>"","pay"=>"","profit"=>"利润");//初始栏目
		$column = $obj->column($this->model,$columnrr,$_POST['acolumn']);
		$column_html = $obj->column_html($this->model,$column);
		$column_json = $obj->form_json($this->model);
		if(empty($this->title)){$this->title = '订单列表';}
		$con->where = "1";
		if($_GET['week']){
			$day_start = date("Y-m-d",strtotime($_GET['week']));
			$day_end = date("Y-m-d",strtotime($_GET['week'])+86400*7);
			$con->where .= " and a.time_add >= '$day_start' and a.time_add < '$day_end' ";
		}
		if($_GET['month']){
			$month = $_GET['month'];
			$con->where .= " and a.time_add LIKE '$month%'";
		}
		//分页函数
		$page->theurl = $this->Aactr.'-'.$this->id;
		$page->order = $this->model->key_name.' DESC';
		$page->page = '16';
		$page->counts = $this->model->count($con);	//统计总数目
		$pages = Afun_apage($page);
		$con->select = "a.*,(a.pay - a.cost) as profit";
		$con->order = "a.$pages->orderby";
		$con->limit = $pages->limit;
		//分页结束
		$list = $this->model->findAll($con);
		//--合计
		$tcon->select = "SUM(a.price) as prices,SUM(a.cost) as costs,SUM(a.pay) as pays,min(a.time_add) as time_min,max(a.time_add) as time_max";
		$tcon->where = $con->where;
		$total = $this->model->find($tcon);
		$days = (strtotime($total['time_max']) - strtotime($total['time_min']))/(3600*24)+1;
		$total['profit'] = $total['pays']-$total['costs'];
		$total['days'] = floor($total['profit']/$days);
		include $this->Atpl();
	}
}

?>